package com.yf1706.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yf1706.bean.CheckAffairApply;
import com.yf1706.bean.CheckAffariCategory;
import com.yf1706.bean.CheckCalendarAffair;
import com.yf1706.bean.CheckFrequency;
import com.yf1706.bean.CheckHolidayKind;
import com.yf1706.bean.CheckNotarizeAffair;
import com.yf1706.bean.CountIncomeTaxRate;
import com.yf1706.bean.Dep;
import com.yf1706.bean.Emp;
import com.yf1706.service.CheckAffairApplyService;
import com.yf1706.service.CheckAffariCategoryService;
import com.yf1706.service.CheckCalendarAffairService;
import com.yf1706.service.CheckFrequencyService;
import com.yf1706.service.CheckNotarizeAffairService;
import com.yf1706.service.DepService;
import com.yf1706.service.EmpService;
import com.yf1706.service.HolidayKindService;
import com.yf1706.tools.JsonTool;
import com.yf1706.vo.CheckCalendarAffairVO;

@Controller
@RequestMapping("check")
public class CheckController extends BaseController{
	@Autowired
	private EmpService es;
	@Autowired
	private DepService ds;
	@Autowired
	private HolidayKindService holidks;
	@Autowired
	private CheckFrequencyService fqs;
	@Autowired
	private CheckNotarizeAffairService cnas;
	@Autowired
	private CheckAffairApplyService aas;
	@Autowired
	private CheckAffariCategoryService cacs;
	@Autowired
	private CheckCalendarAffairService ccas;
	//霍亚宁控制器部分开始
		@RequestMapping("checkBackhome")
		public String check() {
			System.out.println("进入checkBACKhome");
			return "hyn/checkBackhome";
		}
		@RequestMapping("calendar")
		public String calendar() {
			System.out.println("进入事务日历");
			return "hyn/calendar";
		}
		@RequestMapping("checkFlush")
		public String checkFlush() {
			System.out.println("进入刷卡记录界面");
			return "hyn/checkFlush";
		}
		@RequestMapping("checkExcelInCard")
		public String checkExcelInCard() {
			System.out.println("进入刷卡记录界面");
			return "hyn/excelInCard";
		}
		
		@RequestMapping("checkexception")
		public String checkexception() {
			System.out.println("进入考勤异常界面");
			return "hyn/checkexception";
		}
		@RequestMapping("checkadjust")
		public String checkadjust() {
			System.out.println("进入考勤异常调整界面");
			return "hyn/checkadjust";
		}
		@RequestMapping("holidaykind")
		public String holidaykind() {
			System.out.println("进入假种界面");
			return "hyn/holidaykind";
		}
		
		@RequestMapping("checkAddAffairApply")
		public String checkAddAffairApply() {
			System.out.println("进入事假事务申请界面");
			return "hyn/checkAddAffairApply";
		}
		@RequestMapping("checkAddOverTime")
		public String checkAddOverTime() {
			System.out.println("进入添加加班申请界面");
			return "hyn/addOverTime";
		}
		@RequestMapping("checkAffairApply1")
		public String checkAffairApply1() {
			System.out.println("进入事假事务申请界面");
			return "hyn/checkAffairApply1";
		}
		@RequestMapping("checkAffairApply2")
		public String checkAffairApply2() {
			System.out.println("进入事假事务申请界面");
			return "hyn/checkAffairApply2";
		}
		@RequestMapping("checkAffairApply3")
		public String checkAffairApply3() {
			System.out.println("进入事假事务申请界面");
			return "hyn/checkAffairApply3";
		}
		@RequestMapping("checkAffairApply4")
		public String checkAffairApply4() {
			System.out.println("进入补卡申请界面");
			return "hyn/checkAffairApply4";
		}
		@RequestMapping("checkNotarizeAffair")
		public String checkNotarizeAffair() {
			System.out.println("进确认事务申确认界面");
			return "hyn/checkNotarizeAffair";
		}
		@RequestMapping("checkaccount")
		public String checkAcccount() {
			System.out.println("进考勤账套界面");
			return "hyn/checkaccount";
		}
		@RequestMapping("checkwithcard")
		public String checkWithCard() {
			System.out.println("进考勤配卡界面");
			return "hyn/checkwithcard";
		}
		@RequestMapping("checkcomputerule")
		public String checkComputeRuke() {
			System.out.println("进考勤计算规则界面");
			return "hyn/checkComputeRule";
		}
		@RequestMapping("checkrule")
		public String checkRule() {
			System.out.println("进考勤规则界面");
			return "hyn/checkrule";
		}
		@RequestMapping("checkMonthReport")
		public String checkRuleResult() {
			System.out.println("进确认全体员工考勤界面");
			return "hyn/checkMonthReport";
		}
		@RequestMapping("checkAffairCategory")
		public String checkAffairCategory() {
			System.out.println("进确认事务类型界面");
			return "hyn/checkAffairCategory";
		}
		@RequestMapping("checkFrequency")
		public String checkFrequency() {
			System.out.println("进确认班次界面");
			return "hyn/checkFrequency";
		}
		
		//霍亚宁控制器部分结束
		//霍亚宁数据DAO操作开始
		@RequestMapping("getemp")
		@ResponseBody
		public List<Emp> getEmp(){
			 //根据部门编号查询员工
	        List<Emp> list= es.queryAllEmp();
			return list;
		}
		@RequestMapping("getdep")
		@ResponseBody
		public List<Dep> getdep(){
	        List<Dep> list= ds.findAllDep();
			return list;
		}
		//查询全部假种信息
		@RequestMapping("getholidaykind")
		@ResponseBody
		public Map<String, Object> getHolidaylist(int page,int rows){
			Page<CheckHolidayKind> pages = PageHelper.startPage(page, rows);
	        List<CheckHolidayKind> list= holidks.getHolidayKindList();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//查询全部假种信息
		@RequestMapping("getholidaykind2")
		@ResponseBody
		public  List<CheckHolidayKind> getHolidaylist2(){
	        List<CheckHolidayKind> list= holidks.getHolidayKindList();
			return list;
		}
		//模糊查询假种信息
		@RequestMapping("serchHolidayKind")
		@ResponseBody
		public List<CheckHolidayKind> serchHolidayKinds(String serch_jsondata){
			 List<CheckHolidayKind>  list2= holidks.getSerchHolidayKindList(serch_jsondata);
			 return list2;
		}
		//新增假种信息
		@RequestMapping("addHolidayKind")
		@ResponseBody
		public void addHolidayKinds(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 List<CheckHolidayKind> list = JSONObject.parseArray(jsondata, CheckHolidayKind.class);
	         holidks.addHoliday(list.get(0).getHolidayName(), list.get(0).getWhetherSalary(), list.get(0).getRemark(), list.get(0).getPersonageHoliday(), list.get(0).getStatutoryHoliday(), list.get(0).getSystemUse(),getSessionUserName(request));
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//修改假种信息
		@RequestMapping("updateHolidayKind")
		@ResponseBody
		public void updateHolidayKinds(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("update_jsondata");
			 List<CheckHolidayKind> list = JSONObject.parseArray(jsondata, CheckHolidayKind.class);
			 list.get(0).setUpdateEmp(getSessionUserName(request));
			 holidks.updateHoliday(list.get(0));
	         
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//删除假种信息
		@RequestMapping("deleteHolidayKind")
		@ResponseBody
		public void deleteHolidayKinds(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("huo_rowData");
			 List<Integer> list = (List<Integer>) JSONObject.parse(jsondata);	
	       for (Integer o : list) {
	    	   holidks.deleteHoliday(o.intValue());
		}
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		
		//查询全部班次数据
		@RequestMapping("getcheckFrequency")
		@ResponseBody
		public Map<String, Object> getfrequencylist(int page,int rows){
			Page<CheckFrequency> pages = PageHelper.startPage(page, rows);
	        List<CheckFrequency> list= fqs.getfrequencyList();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//模糊查询班次信息
		@RequestMapping("serchcheckFrequency")
		@ResponseBody
		public List<CheckFrequency> serchCheckFrequencys(String frequencyName){
			System.out.println(frequencyName);
			 List<CheckFrequency>  list= fqs.getSerchheckFrequencyList(frequencyName);
			 return list;
		}
		//新增班次信息
		@RequestMapping("addcheckFrequency")
		@ResponseBody
		public void addcheckFrequencys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 System.out.println(jsondata);
			 List<CheckFrequency> list = JSONObject.parseArray(jsondata,CheckFrequency.class);
			 list.get(0).setMaker(getSessionUserName(request));
			 fqs.addCheckFrequency(list.get(0));
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		
		//修改班次信息
		@RequestMapping("updatecheckFrequency")
		@ResponseBody
		public void updatecheckFrequencys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("update_jsondata");
			 List<CheckFrequency> list = JSONObject.parseArray(jsondata, CheckFrequency.class);
			 list.get(0).setUpdateEmp(getSessionUserName(request));
			 fqs.updatecheckFrequency(list.get(0));
	         
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		
		//查询全部事假申请数据
		@RequestMapping("getcheckNotarizeApply")
		@ResponseBody
		public Map<String, Object> getcheckNotarizeApply1(int page,int rows){
			Page<CheckNotarizeAffair> pages = PageHelper.startPage(page, rows);
	        List<CheckNotarizeAffair> list= cnas.getNotarizeAffair();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		
		//模糊查询申请审核信息
		@RequestMapping("serchcheckNotarizeApply")
		@ResponseBody
		public List<CheckNotarizeAffair> serchcheckNotarizeApply(String value){
			 List<CheckNotarizeAffair>  list= cnas.serchcheckNotarizeApply(value);
			 return list;
		}
		//更新事务申请信息
		@RequestMapping("UpdateNotarizeApply")
		@ResponseBody
		public void UpdateNotarizeApply(HttpServletRequest request, HttpServletResponse response){
			 String  id=request.getParameter("notarizeId");
			 String approvalStatus=request.getParameter("approvalStatus");
			 System.out.println(id+approvalStatus);
			 cnas.updateNotarizeApply(Integer.parseInt(id), approvalStatus);
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//查询全部事假申请数据
		@RequestMapping("getcheckAffairApply")
		@ResponseBody
		public Map<String, Object> getcheckAffairApply1(int page,int rows){
			Page<CheckAffairApply> pages = PageHelper.startPage(page, rows);
	        List<CheckAffairApply> list= aas.getAffairApplyList();
	        list.forEach(n->System.out.println(n.getEmp().getDep().getDepName()+"    "+n.getEmp().getEmpName()));
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//模糊查询事假假种信息
		@RequestMapping("serchcheckAffairApply1")
		@ResponseBody
		public List<CheckAffairApply> serchcheckAffairApply1s(String value){
			if(value.equals("")) {
				 int id=-1;
				 List<CheckAffairApply>  list= aas.serchcheckAffairApply1(id);
				 return list;
			}else {
			 int id=Integer.parseInt(value);
			 List<CheckAffairApply>  list= aas.serchcheckAffairApply1(id);
			 return list;
			}
		}
		//删除申请信息
		@RequestMapping("deleteAffairApply")
		@ResponseBody
		public void deleteAffairApplys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 List<Integer> list = (List<Integer>) JSONObject.parse(jsondata);	
	         aas.deleteAffairApply(list.get(0).intValue());
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//新增事务申请信息
		@RequestMapping("addAffairApply")
		@ResponseBody
		public void addAffairApplys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 System.out.println(jsondata);
			 List<CheckAffairApply> list = JSONObject.parseArray(jsondata,CheckAffairApply.class);
			 HttpSession session=request.getSession();
	         String url=(String) session.getAttribute("url");
	         System.out.println("图片路径"+url);
	         list.get(0).setMaker(getSessionUserName(request));
			 cnas.addCheckNotarizeAffai(list.get(0),url);
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//更新事务申请信息
		@RequestMapping("UpdateAffairApply")
		@ResponseBody
		public void updateAffairApplys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 System.out.println(jsondata);
			 List<CheckAffairApply> list = JSONObject.parseArray(jsondata,CheckAffairApply.class);
			 HttpSession session=request.getSession();
	         String url=(String) session.getAttribute("url");
	         System.out.println("图片路径"+url);
			 cnas.addCheckNotarizeAffai(list.get(0),url);
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//查询全部假种申请数据
		@RequestMapping("getcheckAffairApply2")
		@ResponseBody
		public Map<String, Object> getcheckAffairApply2(int page,int rows){
			Page<CheckAffairApply> pages = PageHelper.startPage(page, rows);
	        List<CheckAffairApply> list= aas.getAffairApply2List();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//模糊查询事假假种信息
		@RequestMapping("serchcheckAffairApply2")
		@ResponseBody
		public List<CheckAffairApply> serchcheckAffairApply2s(String value){
			if(value.equals("")) {
				int id=-1;
				 List<CheckAffairApply>  list= aas.serchcheckAffairApply1(id);
				 return list;
			}else {
			 int id=Integer.parseInt(value);
			 List<CheckAffairApply>  list= aas.serchcheckAffairApply1(id);
			 return list;
			}
		}
		//查询全部假种申请数据
		@RequestMapping("getcheckAffairApply3")
		@ResponseBody
		public Map<String, Object> getcheckAffairApply3(int page,int rows){
			Page<CheckAffairApply> pages = PageHelper.startPage(page, rows);
	        List<CheckAffairApply> list= aas.getAffairApply3List();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//模糊查询事假假种信息
		@RequestMapping("serchcheckAffairApply3")
		@ResponseBody
		public List<CheckAffairApply> serchcheckAffairApply3s(String value){
			if(value.equals("")) {
				 int id=-1;
				 List<CheckAffairApply>  list= aas.serchcheckAffairApply3(id);
				 return list;
			}else {
			 int id=Integer.parseInt(value);
			 List<CheckAffairApply>  list= aas.serchcheckAffairApply3(id);
			 return list;
			}
		}
		//查询全部事务类别数据
		@RequestMapping("getcheckAffairCategory")
		@ResponseBody
		public Map<String, Object> getcheckAffairCategorys(int page,int rows){
			Page<CheckAffariCategory> pages = PageHelper.startPage(page, rows);
	        List<CheckAffariCategory> list= cacs.getCheckAffairCategoryList();
	        Map<String, Object> map = new HashMap<String, Object>();
	        long total = pages.getTotal();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		//查询全部事务类别数据,应用于行政日历
		@RequestMapping("getcheckAffairCategory2")
		@ResponseBody
		public List<CheckAffariCategory> getcheckAffairCategorys2(){
	        List<CheckAffariCategory> list= cacs.getCheckAffairCategoryList();
			return list;
		}
		//模糊查询假种信息
		@RequestMapping("serchAffairCategory")
		@ResponseBody
		public List<CheckAffariCategory> serchAffairCategorys(String serch_jsondata){
			 List<CheckAffariCategory>  list= cacs.getSerchAffairCategoryList(serch_jsondata);
			 return list;
		}
		//新增事务类型信息
		@RequestMapping("addAffairCategory")
		@ResponseBody
		public void addAffairCategorys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 System.out.println(jsondata);
			 List<CheckAffariCategory> list = JSONObject.parseArray(jsondata, CheckAffariCategory.class);
	        list.get(0).setMaker(getSessionUserName(request));
			 cacs.addAffariCategory(list.get(0));
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//删除指定事务类别数据
		@RequestMapping("deleteCheckAffairCategory")
		@ResponseBody
		public void deletecheckAffairCategorys(HttpServletRequest request, HttpServletResponse response){
		 String jsondata=request.getParameter("huo_rowData");
		 List<Integer> list = (List<Integer>) JSONObject.parse(jsondata);	
	       for (Integer o : list) {
	    	   cacs.deleteAffariCategory(o.intValue());
		}
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//修改假种信息
		@RequestMapping("updateAffairCategory")
		@ResponseBody
		public void updateAffairCategorys(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("update_jsondata");
			 List<CheckAffariCategory> list = JSONObject.parseArray(jsondata, CheckAffariCategory.class);
			 list.get(0).setUpdateEmp(getSessionUserName(request));
			 cacs.updateAffairCategory(list.get(0));
	         
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//查询全部日历事务数据
		@RequestMapping("getcalendarAffair")
		@ResponseBody
		public List<CheckCalendarAffair> getcalendarAffairs(){
	        List<CheckCalendarAffair> list=ccas.getCalendarAffairList();
			return list;
		}
		//新增行政事务信息
		@RequestMapping("addcalendarAffair")
		@ResponseBody
		public void addcalendarAffairs(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("jsondata");
			 System.out.println(jsondata);
			 List<CheckCalendarAffairVO> list = JSONObject.parseArray(jsondata, CheckCalendarAffairVO.class);
			 ccas.addcalendarAffair(list.get(0));
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//修改行政事务信息
		@RequestMapping("updatecalendarAffair")
		@ResponseBody
		public void updatecalendarAffairs(HttpServletRequest request, HttpServletResponse response){
			 String jsondata=request.getParameter("update_jsondata");
			 List<CheckCalendarAffairVO> list = JSONObject.parseArray(jsondata, CheckCalendarAffairVO.class);
			 ccas.updatecalendarAffair(list.get(0));
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//模糊查询行政事务信息
		@RequestMapping("serchcalendar")
		@ResponseBody
		public List<CheckCalendarAffair> serchcalendars(String begin,String end,String affairName){
			System.out.println(begin+end+affairName);
			if(begin.equals("")&&end.equals("")) {
			String begin1=null;
			String end1=null;
			 System.out.println(begin+end+affairName);
			 List<CheckCalendarAffair>  list= ccas.serchcalendars(begin1,end1,affairName);
			 return list;
			}else if(begin.equals("")){
				String begin1=null;
				 List<CheckCalendarAffair>  list= ccas.serchcalendars(begin1,end,affairName);
				 return list;		
			}else if(end.equals("")){
				 String end1=null;
				 List<CheckCalendarAffair>  list= ccas.serchcalendars(begin,end1,affairName);
				 return list;		
			}else {
				 List<CheckCalendarAffair>  list= ccas.serchcalendars(begin,end,affairName);
				 return list;
			}
			
		}
		//删除指定事务类别数据
		@RequestMapping("deletecalendarAffair")
		@ResponseBody
		public void deletecalendarAffairs(HttpServletRequest request, HttpServletResponse response){
		 String jsondata=request.getParameter("huo_rowData");
		 System.out.println(jsondata);
		 List<Integer> list = (List<Integer>) JSONObject.parse(jsondata);	
	       for (Integer o : list) {
	    	   ccas.deletecalendarAffair(o.intValue());
		}
	         PrintWriter out;
				try {
					out = response.getWriter();
					out.print("ok");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}
		//霍亚宁数据DAO操作结束
}
